---
title: "Get Chat Availability"
api: "GET https://api-v2.opencopilot.so/backend/reports/{orgId}/chats/availability"
description: "Retrieve the chat availability statistics for a specified time period"
---

## Authentication

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication
</ParamField>

### Path Parameters

<ParamField path="orgId" type="string" required>
  The ID of the organization to retrieve chat availability for
</ParamField>

### Query Parameters

<ParamField query="startDate" type="string" required>
  The start date for the report period (ISO 8601 format)
</ParamField>

<ParamField query="endDate" type="string" required>
  The end date for the report period (ISO 8601 format)
</ParamField>

<ParamField query="channel" type="string" optional>
  The specific channel to filter results (if applicable)
</ParamField>

### Response

<ResponseField name="availability_percentage" type="number">
  The availability percentage as a number between 0 and 100
</ResponseField>

<ResponseField name="down_times" type="array">
  An array of objects representing periods of downtime
</ResponseField>

<ResponseField name="down_times[].start_time" type="string">
  The start time of the downtime period (ISO 8601 format)
</ResponseField>

<ResponseField name="down_times[].end_time" type="string">
  The end time of the downtime period (ISO 8601 format)
</ResponseField>

<ResponseField name="down_times[].duration" type="number">
  The duration of the downtime period in milliseconds
</ResponseField>

<ResponseField name="down_times[].session_id" type="string">
  The session ID associated with the downtime period
</ResponseField>

<ResponseField name="total_down_time" type="number">
  The total downtime in milliseconds for the specified period
</ResponseField>

<ResponseField name="total_time" type="number">
  The total time in milliseconds for the specified period
</ResponseField>

<RequestExample>

```bash Example Request
curl --location --request GET 'https://api-v2.opencopilot.so/backend/reports/123456/chats/availability?startDate=2023-01-01T00:00:00Z&endDate=2023-01-31T23:59:59Z' \
--header 'Authorization: Bearer YOUR_API_KEY'
```

</RequestExample>

<ResponseExample>

```json Response
{
  "availability_percentage": 98.5,
  "down_times": [
    {
      "start_time": "2023-01-15T10:30:00Z",
      "end_time": "2023-01-15T11:00:00Z",
      "duration": 1800000,
      "session_id": "session123"
    },
    {
      "start_time": "2023-01-20T14:45:00Z",
      "end_time": "2023-01-20T15:00:00Z",
      "duration": 900000,
      "session_id": "session456"
    }
  ],
  "total_down_time": 2700000,
  "total_time": 2678400000
}
```

</ResponseExample>


### Calculation Method

The chat availability is calculated using the following method:

1. **Message Gap Analysis**: The system analyzes the time gaps between consecutive messages within the specified date range.

2. **Downtime Threshold**: A gap of more than 2 minutes between messages is considered as potential downtime.

3. **Downtime Calculation**: For each gap exceeding 2 minutes, the downtime is calculated as:
   ```
   Downtime = (Time between messages) - 2 minutes
   ```

4. **Total Downtime**: The system sums up all individual downtimes to get the total downtime.

5. **Availability Percentage**: The availability percentage is calculated as:
   ```
   Availability % = ((Total Time - Total Downtime) / Total Time) * 100
   ```
   Where Total Time is the duration between the specified start and end dates.